local dingpan = fk.CreateSkill{
  name = "wk_heg__dingpan",
  tags = { Skill.MainPlace },
}

Fk:loadTranslationTable{
  ["wk_heg__dingpan"] = "定叛",
  [":wk_heg__dingpan"] = "主将技，此武将牌上单独的阴阳鱼个数-1；出牌阶段限X次，你可令一名其他势力角色摸一张牌，然后其交给你其攻击范围数张牌或令你视为对其使用一张【杀】（X为野心家角色数+1）。",

  ["wk_heg__dingpan_use"] = "定叛：视为%src对你使用【杀】",
  ["#wk_heg__dingpan_give"] = "定叛：交出%arg张牌",
  ["#wk_heg__dingpan"] = "定叛：选择一名其他势力角色令其摸一张牌",

  ["$wk_heg__dingpan1"] = "从孙者生，从刘者死！",
  ["$wk_heg__dingpan2"] = "多行不义必自毙！",
}

local H = require "packages/ol_hegemony/util"

dingpan:addEffect("active",{
  anim_type = "offensive",
  prompt = "#wk_heg__dingpan",
  can_use = function(self, player)
    local room = Fk:currentRoom()
    local n = 0
    for _, p in ipairs(room.alive_players) do
      if p.kingdom == "wild" then
        n = n + 1
      end
    end
    return player:usedSkillTimes(dingpan.name, Player.HistoryPhase) < n + 1
  end,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player,to_select, selected)
  return #selected == 0 and to_select ~= player and
    (not H.compareKingdomWith(to_select, player))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    target:drawCards(1, dingpan.name)
    local n = target:getAttackRange()
    local choices = {"wk_heg__dingpan_use:"..player.id}
    if n <= #target:getCardIds("he") then
      table.insert(choices, "#wk_heg__dingpan_give:::"..n)
    end
    local choice = room:askToChoice(target, {choices = choices,skill_name = dingpan.name})
    if choice:startsWith("wk_heg__dingpan_use") then
      room:useVirtualCard("slash", nil, player, target, dingpan.name, true)
    else
      local cards = room:askToChooseCards(target,{
        target = target,
        min = n,
        max = n,
        flag = "he",
        skill_name = dingpan.name,
      })
      room:moveCardTo(cards, Card.PlayerHand, player, fk.ReasonGive, dingpan.name, nil, false, player.id)
    end
  end,
})

return dingpan